package org.xutils.db;

import android.app.Application;

import org.xutils.db.def.OnGenUUIDCallback;
import org.xutils.db.ex.DbException;
import org.xutils.db.impl.DbManagerImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created by ZZH on 4/19/21.
 *
 * @Date: 4/19/21
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 单例模式
 */
public class xDb {
    private xDb() {
    }

    private boolean isDebug = false;

    public boolean isDebug() {
        return isDebug;
    }

    public void setDebug(boolean debug) {
        isDebug = debug;
    }

    private Application ctx;
    private static xDb mXDb;

    public static DbManager getDb(DbManager.DaoConfig config) throws DbException {
        return DbManagerImpl.getInstance(config);
    }

    public Application getContext() {
        return ctx;
    }

    public void init(Application ctx) {
        this.ctx = ctx;
        System.loadLibrary("sqlcipher");
    }


    public static xDb getInstance() {
        if (mXDb == null) {
            synchronized (xDb.class) {
                if (mXDb == null) {
                    mXDb = new xDb();
                }
            }
        }
        return mXDb;
    }

    OnGenUUIDCallback mCallback;

    public void registerGenUUID(OnGenUUIDCallback callback) {
        mCallback = callback;
    }

    public String generate() {
        if (mCallback != null) {
            return mCallback.generate();
        } else {
            return UUID.randomUUID().toString();
        }
    }

    public List<String> getTables() {
        return new ArrayList<>();
    }
}
